package com.zrrd.learn.chapter07字符串;

/**
 * 中间项
 *
 * @author wrn
 * @version 1.0
 * @date 2023/7/20 13:13
 */

public class StringTest03 {

    public static void question() {

        int[] arr = {1,2,3,4,3,2,1};
        int sum = 0;
        int sumq = 0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        System.out.println("数组元素总和为"+sum);
        if (arr.length==1){
            System.out.println("数组中间项是自己本身");
        }else if(arr.length==2&&arr[1]==0){
            System.out.println("数组中间项下标为"+0+"数组中间项是"+arr[0]);
        }else {
            for (int i = 1; i < arr.length; i++) {
                sumq+=arr[i-1];
                L:if (sumq*2==sum-arr[i]){
                    System.out.print("数组中间项下标为");
                    System.out.println(i+"中间项为"+arr[i]);
                }else if(sumq*2==sum-arr[i]&&i==arr.length-1){
                    System.out.println("数组无中间项");
                } else {
                    System.out.println("数组无中间项");
                }
            }
        }

    }

    public static void main(String[] args) {
        question();
    }


}
